﻿using System;

namespace Borg
{
    [Serializable]
    internal class EventHandlerWrapper<T>
    {
        private readonly EventHandler<T> _eventHandler;

        public EventHandler<T> EventHandler
        {
            get { return _eventHandler; }
        }

        public EventHandlerWrapper(EventHandler<T> eventHandler)
        {
            if (eventHandler == null)
                throw new ArgumentNullException("eventHandler");
            
            _eventHandler = eventHandler;
        }

        public void Invoke(T args)
        {
            _eventHandler(args);
        }

        public override bool Equals(object obj)
        {
            if (this == obj)
                return true;
            
            if (!(obj is EventHandlerWrapper<T>))
                return false;
            
            return _eventHandler.Equals(((EventHandlerWrapper<T>)obj)._eventHandler);
        }

        public override int GetHashCode()
        {
            return _eventHandler.GetHashCode();
        }
    }
}
